/**

This file is part of MaCI/GIMnet.

MaCI/GIMnet is free software: you can redistribute it and/or modify it 
under the terms of the GNU Lesser General Public License as published 
by the Free Software Foundation, either version 3 of the License, or 
(at your option) any later version.

MaCI/GIMnet is distributed in the hope that it will be useful, but WITHOUT 
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 
FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public 
License for more details.

You should have received a copy of the GNU Lesser General Public 
License along with GIMnet. (See COPYING.LESSER) If not, see 
<http://www.gnu.org/licenses/>.

**/
/**
 * \file
 * \brief Simple mechanism for launching AP services together with the AP - header.
 * \author Antti Maula <antti.maula@tkk.fi>
 */
#ifndef _GIMNETAP_SERVICELAUNCHER_H_
#define _GIMNETAP_SERVICELAUNCHER_H_

#include <unistd.h>


/** Launch a service.
 *
 * This function launches a service.
 *
 * @param[in] application       Name of application (inc. path)
 * @param[in] arguments         execv(2) compatible argument list.
 * @return                      Process id of new child, or negative on error.
 */
pid_t servicelauncherLaunchService(const char *application, char *const* arguments);


/** Signal a service.
 * 
 * This function sends a signal to given process. This function is essentially
 * a wrapped kill(2).
 *
 * @param[in] process           Process id to signal
 * @param[in] sig               Signal to send.
 * @return                      zero on success, negative on error.
 */
int servicelauncherSignalService(const pid_t process, const int sig);


/** Query service status.
 *
 * This function queries the service process for status changes. The
 * function is intended for detecting whether service has terminated
 * uncontrollably.
 *
 * @param[in] process           Process id to check.
 * @return                      negative on error, zero when process still running,
 *                              positive when process has terminated.
 */
int servicelauncherGetServiceStatus(const pid_t process);


/** Wait for service termination.
 * 
 * This function sits and waits forever until the given process has
 * terminated.
 *
 * @param[in] process           Process id to wait.
 * @return                      positive when wait was completed succesfully and process
 *                              has exited, negative on error (for example; no such process,
 *                              or already waited)
 */
int servicelauncherWaitService(const pid_t process);


#endif
